home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap02 / howto01 / drwsutl1.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-02-29  |  1.3 KB  |  44 lines

  1. unit Drwsutl1;
  2.  
  3. interface
  4. uses
  5.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  6.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, ShellAPI, FileCtrl;
  7.  
  8. function ShellExec(const PathStr, CmdStr, DirStr: string;
  9.   PrintIt: boolean; Show: word; Wait: boolean): boolean;
  10. implementation
  11.  
  12. { This function is from Delphi How To Copyright 1995 Waite Group Press }
  13. function ShellExec(const PathStr, CmdStr, DirStr: string;
  14.   PrintIt: boolean; Show: word; Wait: boolean): boolean;
  15. var
  16.   Inst: THandle;
  17.   Path, CmdLine, Dir: PChar;
  18.   Op: array[0..5] of Char;
  19. begin
  20.   if PrintIt then StrPCopy(Op, 'print') else StrPCopy(Op, 'open');
  21.   { Get memory for PChars }
  22.   GetMem(Path, Length(PathStr)+1);
  23.   GetMem(CmdLine, Length(CmdStr)+1);
  24.   GetMem(Dir, Length(DirStr)+1);
  25.   try
  26.     { Copy strings to PChars }
  27.     StrPCopy(Path, PathStr);
  28.     StrPCopy(CmdLine, CmdStr);
  29.     StrPCopy(Dir, DirStr);
  30.     { Execute file }
  31.     Inst := ShellExecute(0, Op, Path, CmdLine, Dir, Show);
  32.     { If 32 or less, an error occurred }
  33.     if Inst <= 32 then Result := False else Result := True;
  34.   finally
  35.     { Ensure memory is freed }
  36.     FreeMem(Path, Length(PathStr)+1);
  37.     FreeMem(CmdLine, Length(CmdStr)+1);
  38.     FreeMem(Dir, Length(DirStr)+1);
  39.   end;
  40. end;
  41.  
  42.  
  43. end.
  44.